<?php
/*
 * 
 *  魔兽世界数据库
 * 
 * */

class WowController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    	$menu = new Model_Dbtable_Wowmenu();
		$this->view->menu = $menu->menu();
		$this->view->showurl = "/".Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
		$this->_helper->layout->setLayout('wow');
    }

    public function indexAction()
    {
    	
    	$db = new Model_Dbtable_Wowmenu();
    	$this->view->allmenu = $db->allmenu()->toArray();
        // action body
        $this->view->headTitle("魔兽世界数据库", 'PREPEND');
        $this->view->headMeta()->setName('keywords', "熊猫人之迷,魔兽世界数据库");

    }

    public function itemAction()
    {
    	$id = $this->_request->getParam('id');
		$db = new Model_Dbtable_Wowitem();
		$nav = new Model_Core_Nav();
		
    	if ($id){
    		//VIEW ITEM

			$content = $db->showitem($id);
			$content[specs] = preg_replace("/<a [^>]*>|<\/a>/i", "", $content[specs]);
			
    		$this->view->content = $content;
    		
    		$this->view->nav = $nav->nav('wow', 'item', "$content[name]", $content[classid], $content[subid]);
    		
    		$this->view->headTitle("$content[name] - 物品列表 - 魔兽世界数据库", 'PREPEND');
	        $this->view->headMeta()->setName('keywords', "$content[name],物品列表,熊猫人之迷,魔兽世界数据库");
	    	$this->render('itemview');
	    	
    	}else{
    		
    		//ITEM LIST
    		$class 	 = $this->_request->getParam('class', -1);
	    	$sub 	 = $this->_request->getParam('sub', -1);
	    	$invtype = $this->_request->getParam('invtype', -1);
	    	$page 	 = $this->_request->getParam('page', 1);
	    	$purl	 = Zend_Controller_Front::getInstance()->getRequest()->getActionName();
			
			$row = $db->showlist($class, $sub, $invtype, $page, $purl);
			$this->view->showlist = $row[results];
			$this->view->multipage = $row[multipage];
			
			
    		$this->view->nav = $nav->nav('wow', 'item', "", $class, $sub);
    		
    		$list_nav = new Model_Core_Navtop();
    		$list_nav = $list_nav->navtop('wow', 'item', $class, $sub);
    		
    		$this->view->navtop = $list_nav[navtop];
    		$this->view->navbottom = $list_nav[navbottom];
    		
	        $this->view->headTitle("物品列表 - 魔兽世界数据库", 'PREPEND');
	        $this->view->headMeta()->setName('keywords', "物品列表,熊猫人之迷,魔兽世界数据库");
	    	$this->render('itemlist');
    	}
    	
    	
    }
    
    public function sitemapAction()
    {
    	$nav = '<li><span class="right">></span><a href="/sitemap">网站地图</a></li>';
    	$this->view->nav = $nav;
    }
    
    public function searchAction()
    {
    	$page 	 = $this->_request->getParam('page', 1);
    	$query 	 = trim(strip_tags($this->_request->getParam('q')));
    	$purl	 = Zend_Controller_Front::getInstance()->getRequest()->getActionName();
    	$mod	 = $this->_request->getParam('mod', 'item');
		
    	if ($mod == "item"){
    		$sql = new Model_Dbtable_Wowitem();
    		$where = " name LIKE '%$query%' OR item_id LIKE '%$query%'";
    		$row = $sql->showlist("-1", "-1", "-1", $page, $purl."?mod=$mod&q=".$query, $where);
    		$showlist = "itemlist";
    	}elseif ($mod == "spell"){
    		$sql = new Model_Dbtable_Wowspell();
    		$where = " name LIKE '%$query%' OR id LIKE '%$query%'";
    		$showlist = "spelllist";
    		$row = $sql->showlist("-1", $page, $purl."?mod=$mod&q=".$query, $where);
    	}
    	
    	
		$this->view->showlist = $row[results];
		$this->view->multipage = $row[multipage];
		
		
		$this->view->query = $query;
		$this->view->actionname = $purl;
		$nav = new Model_Core_Nav();
    	$this->view->nav = $nav->nav('wow', '', "搜索列表");
    	$this->render($showlist);
    }
    
   	
   	public function spellAction()
   	{
   		$id = $this->_request->getParam('id');
		$db = new Model_Dbtable_Wowspell();
		$nav = new Model_Core_Nav();
		
    	if ($id){

		    $content = $db->showitem($id);
			
    		$this->view->content = $content;
    		
    		$this->view->nav = $nav->nav('wow', 'spell', "$content[name]", $content[classid]);
    		
    		$this->view->headTitle("$content[name] - 物品列表 - 魔兽世界数据库", 'PREPEND');
	        $this->view->headMeta()->setName('keywords', "$content[name],物品列表,熊猫人之迷,魔兽世界数据库");
	    	$this->render('spellview');

    	}else{
			$class 	 = $this->_request->getParam('class', -1);    
	    	$page 	 = $this->_request->getParam('page', 1);
	    	$purl	 = Zend_Controller_Front::getInstance()->getRequest()->getActionName();
			
			$row = $db->showlist($class, $page, $purl);
			$this->view->showlist = $row[results];
			$this->view->multipage = $row[multipage];
			
			
    		$this->view->nav = $nav->nav('wow', 'spell', "", $class);
    		
    		$list_nav = new Model_Core_Navtop();
    		$list_nav = $list_nav->navtop('wow', 'spell', $class, $sub);
    		
    		$this->view->navtop = $list_nav[navtop];
    		
	        $this->view->headTitle("技能列表 - 魔兽世界数据库", 'PREPEND');
	        $this->view->headMeta()->setName('keywords', "技能列表,熊猫人之迷技能,魔兽世界数据库");
	    	$this->render('spelllist');
		}
	    		
   	}
}

